var _tools = require("../../../utils/tools.js"), _tools2 = _interopRequireDefault(_tools);

function _interopRequireDefault(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

var that, app = getApp();
let interstitialAd = null;

Page({
    data: {
        request: 1,
        show_succ: !1
    },
    onLoad: function() {
        that = this;
    },
    onReady: function() {
        wx.setNavigationBarColor({
            frontColor: "#000000",
            backgroundColor: "#000000"
        });
        var t = {
            action: "coupon",
            contr: "my",
            token: wx.getStorageSync("token")
        };
        _tools2.default.request(t, function(t) {
            that.setData(t.info);
        });
    },
    onShow: function() {
        if (wx.createInterstitialAd) {
            interstitialAd = wx.createInterstitialAd({
              adUnitId: 'adunit-42e141bfcfdcc315'
            })
            interstitialAd.onLoad(() => {})
            interstitialAd.onError((err) => {})
            interstitialAd.onClose(() => {})
          };
          
          // 在适合的场景显示插屏广告
          if (interstitialAd) {
            interstitialAd.show().catch((err) => {
              console.error(err)
            })
          };
    },
    exchange: function(t) {
        var a = t.currentTarget.dataset.index;
        if (this.data.coupon[a].integral > this.data.member.integral) wx.showToast({
            icon: "none",
            title: this.data.config.integral_name + "不足"
        }); else if (1 == this.data.request) {
            this.data.request = 2;
            var e = {
                action: "exchangeCoupon",
                contr: "my",
                token: wx.getStorageSync("token"),
                id: this.data.coupon[a].id
            };
            _tools2.default.request(e, function(t) {
                that.data.request = 1, 2 == t.status ? wx.showModal({
                    title: "提示",
                    mask: !0,
                    content: t.info,
                    showCancel: !1
                }) : (that.succ_status(), that.onReady());
            });
        }
    },
    succ_status: function() {
        this.setData({
            show_succ: !this.data.show_succ
        });
    },
    gotoMyBargain: function() {
        wx.navigateTo({
            url: "/bh_bargain/pages/myBargain/myBargain"
        });
    },
    onShareAppMessage: function() {
        return {
            title: this.data.share.text,
            imageUrl: this.data.share.images,
            path: "bh_bargain/pages/index/index?parent_id=" + this.data.share.member_id
        };
    }
});